<ul>
    <?php foreach ($materialList as $key=>$rs):?>
    <li class="material_Li"  onclick="getsku(<?=$rs['id']?>)" style="margin-top: -5px">
            <a href="javascript:void(0)"><?=$this->uri->segment(1)=='english'?"<span style='color: #0000FF;width:200px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis;display: inline-block ;vertical-align:top;' title='".$rs['name_cn']."'>".$rs['name_cn']."</span>":"<span style='color: #0000FF;'>".$rs['name_cn']."</span>";?>
            <?=$this->uri->segment(1)=='sc'?"<span style='width:250px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis;display: inline-block ;vertical-align:top;' title='".$rs['name']."'>".$rs['name']."</span>":$rs['name'];?>
            <span style="color: #0000FF;margin-left: 5px;font-size: 14px;"><?=$rs['sku']?></span></a>
    </li>
    <?php endforeach;?>
</ul>
<script type="text/javascript">
    function getsku(id){
        if(!id){
            alert('id is null');
            $("input[name='accessory_name']").val('');
            return false;
        }
        $.post("<?=blang_url('ajax/ajax/ajaxMaterialOne')?>", {'id':id,'mtid':$('#mtid').val()},function(data){
            var obj = JSON.parse(data);
            console.log(obj);
            $("input[name='accessory_name']").val(obj.name);
            $("input[name='sku']").val(obj.sku);
            $("input[name='accessory_price']").val(obj.price);
            $("input[name='accessory_cost']").val(obj.cost);
            $("input[name='purchase_source']").val(obj.currency);
            $("#currency").text(obj.currency);
            $("#cucy").val(obj.currency);
            $("input[name='mt_site']").val(obj.site);
            if(obj.stars==1) {
                $("input[name='name_cn']").val(obj.name_cn);
            }else{
                $("input[name='name_cn']").val();
            }
            $("input[name='wid']").val(obj.id);
            $("#search_auto").css({'display':'none'});

            if(obj.stars==1){
                if(obj.shuliang>0){
                    $("input[name='quantity']").val(obj.shuliang);
                }else{
                    $("input[name='quantity']").val(0);
                    $('#loadingDiv').css('display','block');
                    $('#yjieguo').css('display','block');
                    $('#mjieguo').css('display','none');
                    $('#popup').slideDown();
                }
            }
            $(document).on('click','a',function(){
                if($(this).text()=="确定" || $(this).text()=="Determine"){
                    if(obj.stars==1) {
                        if($("#number1").val()==''){
                            alert("<?=lang('pcm_slbnwk')?>");
                            return false;
                        }
                        if(isNaN($("#number1").val())){
                            alert("<?=lang('pcm_slbxssz')?>");
                            return false;
                        }
                        $("#caigou1").submit();
                    }
                }else{
                    $('#loadingDiv').css('display','none');
                    $('#popup').slideUp();
                }
            });
        });
    }

</script>
